$(document).ready(function() {
    $('#icon_upload').uploadify({
		    'uploader'  : '/js/adminbase/uploadify/uploadify.swf',
		    'script'    : '/js/adminbase/uploadify/uploadify.php',
		    'cancelImg' : '/js/adminbase/uploadify/cancel.png',
		    'folder'    : '/images/product/icon',
		 	'onComplete'  : function(event, ID, fileObj, response, data) {  
			  	showimageicon("icon",response);
		  		},
		    'auto'      : true
	  });
  $('#file_upload').uploadify({
	    'uploader'  : '/js/adminbase/uploadify/uploadify.swf',
	    'script'    : '/js/adminbase/uploadify/uploadify.php',
	    'cancelImg' : '/js/adminbase/uploadify/cancel.png',
	    'folder'    : '/file',
	 	'onComplete'  : function(event, ID, fileObj, response, data) {  
	 	     $('#file_size').val(fileObj.size);
		  	showfilename("link_download", response);
	  		},
	    'auto'      : true
  });
  $(".close").click(function(){
        $(".notification").remove();
  });
});
// dang dung
function showimage(name_id,image_link){
	var nameold = jQuery("#"+name_id).val();
	var count_images = jQuery("#count_images").val();
	var namenew;
	if(nameold) namenew = nameold + "||" + image_link;
	else namenew = image_link;
	jQuery("#"+name_id).val(namenew);
	var html = "<span id='images_view"+count_images+"'><img src='"+image_link+"' width='100' height ='100'/><img src='/images/adminbase/delete.png' width='20' height ='20' onclick=delete_images('images_view"+count_images+"','"+image_link+"') /></span>";
	jQuery("#count_images").val(count_images + 1);
	jQuery("#add_images").append(html);
}

// dang dung
function showimageicon(name_id,image_link){
	jQuery("#"+name_id).val(image_link);
	var image = "<img src='"+image_link+"' />";
	jQuery("#show_"+name_id).html(image);
}
// dang dung
function showfilename(name_id,file_link){
    jQuery("#"+name_id).css("display", "block");
	jQuery("#"+name_id).val(file_link);
}

// dang dung
function showFormAdd(){
    $("#formedit").hide();
	$("#formadd").show();
}
// dang dung
function showFormEdit(id){
//	alert(id);
	$("#formadd").hide();
	$("#formedit").show();
	$("#temp").val(id);
}
// dang dung
function edit_account(id){
	
	url = '/admin/admin/editaccount?id='+id;
	$("#formnew").load(url);
	
	$("#formnew").fadeIn();
	$("#formadd").remove();
}
// dang dung
function addaccount(id){
	
	url = '/admin/admin/addaccount';
	$("#formnew").load(url);
	
	$("#formnew").fadeIn();
	$("#formedit").remove();
}
// dang dung
function editsite(id){
	
	url = '/admin/index/editsite?id='+id;
	$("#formnew").load(url);
	
	$("#formnew").fadeIn();
	$("#formadd").remove();
}
function addsite(){
	url = '/admin/index/addsite';
	$("#formnew").load(url);
	
	$("#formnew").fadeIn();
	$("#formedit").remove();
}
// dang dung
function delete_account(id){
	var comfirmBox;
	 comfirmBox = confirm("Bạn có chác chắn muốn xóa không ?");
	 if(comfirmBox == true)
	  {
		 $.ajax(
			      {
			    	  type:"POST",
					  url: "/admin/admin/deleteaccount",
					  data: "id=" + id,
					  datatype: "html",
					  success: function(html)
					     {
						  $("#" + id).remove();
					     }
			      }
			      );
	  }
}
// dang dung
function delete_site(id){
	var comfirmBox;
	 comfirmBox = confirm("Bạn có chác chắn muốn xóa không ?");
	 if(comfirmBox == true)
	  {
		 $.ajax(
			      {
			    	  type:"POST",
					  url: "/admin/index/deletesite",
					  data: "id=" + id,
					  datatype: "html",
					  success: function(html)
					     {
						  $("#" + id).remove();
					     }
			      }
			      );
	  }
}

// dang dung
function edit_status(id,status){
	   var comfirmBox;
	   comfirmBox = confirm("Bạn có chắc chắn muốn thay đổi ?");
	   if(comfirmBox == true)
		  {
		   $.ajax(
		      {
		    	  type:"POST",
				  url: "/admin/admin/editstatus",
				  data: "id=" + id + "&status=" + status,
				  datatype: "html",
				  success: function(html)
				     {
					  
						    $("#" + id).empty();
						    $("#"+ id).prepend(html);
					 }
			 });
		   
		  }
}

/**
 * 
**/
function showForm(name){
	$("#"+name).show();
}
function check(){
	var keyword=$("#keyword").val();
	if(keyword == "" || keyword == 0){
		alert("Nội dung không chính xác");
		$("#keyword").focus;
		return false;
	}
	$("#addForm").submit;
}
function change_status(status,object_id,url){
    $.ajax({
       url: url,
       type: 'POST',
       data: 'object_id='+object_id+'&status='+status,
       success: function(data){
        if(status==0){
            $("#status"+object_id).html("OFF");
            $("a:has(#status"+object_id+")").attr("href","javascript:change_status(1,"+object_id+",'"+url+"')");
        }
        else{
            $("#status"+object_id).html("ON");
            $("a:has(#status"+object_id+")").attr("href","javascript:change_status(0,"+object_id+",'"+url+"')");
        }
       },
       error: function(data){
        alert(data);
       }
    });
    
}
function checkAll(check){
    var elements= document.getElementsByName("things[]");
    for(var i=0;i<elements.length;i++){
        elements[i].checked=check;
    } 
}

// dang dung	
	function delete_images(id,images){
	      jQuery("#"+id).remove();
		  var string_images = jQuery("#intro_image").val();
		  if(string_images.indexOf("||"+images) != -1)
			var string_images_new = string_images.replace('||'+images, "");
		  else var string_images_new = string_images.replace(images, "");
		  jQuery("#intro_image").val(string_images_new);
	}

